class Solution(object):
    def maxBoxesInWarehouse(self, boxes, warehouse):
        n = len(warehouse)
        for i in range(1, n):
            warehouse[i] = min(warehouse[i - 1], warehouse[i])
        warehouse.reverse()
        boxes.sort()
        m = len(boxes)
        left = 0
        right = 0
        ans = 0
        while left < m and right < n:
            if boxes[left] <= warehouse[right]:
                left += 1
                right += 1
                ans += 1
            else:
                right += 1
        return ans